<template>
  <div class="common-layout">
    <el-container>
      <el-header>
        <el-row :gutter="20">
          <el-col :span="4"><img src="../assets/logo.jpg" class="logo" /></el-col>
          <el-col :span="18"><h2>商城后台管理系统</h2></el-col>
          <el-col :span="2">
            <el-dropdown class="quit-login">
              <span class="el-dropdown-link">
                {{ Number(role) ? `管理员${username}` : `商家${username}`
                }}<el-icon class="el-icon--right">
                  <arrow-down />
                </el-icon>
              </span>
              <template #dropdown>
                <el-dropdown-menu>
                  <el-dropdown-item @click="logout">退出登录</el-dropdown-item>
                </el-dropdown-menu>
              </template>
            </el-dropdown>
          </el-col>
        </el-row></el-header
      >
      <el-container>
        <el-aside width="200px">
          <el-menu
            active-text-color="#ffd04b"
            background-color="#545c64"
            class="el-menu-vertical-demo"
            :default-active="url ? url : '/goods'"
            text-color="#fff"
            router
          >
            <!-- router开启路由模式， 通过el-menu-item来进行跳转 -->
            <!-- <ElRoute :arrList="list"></ElRoute> -->
            <el-menu-item :index="item.path" v-for="item in list" :key="item.path">
              <span>{{ item.meta.title }}</span>
            </el-menu-item>
          </el-menu>
        </el-aside>
        <el-main>
          <!-- 设置路由出口 -->
          <router-view></router-view>
        </el-main>
      </el-container>
    </el-container>
  </div>
</template>

<script lang="ts" setup>
import ElRoute from "@/components/ElRoute.vue";
import { ArrowDown } from "@element-plus/icons-vue";
import { useRouter, useRoute } from "vue-router";
import { computed, ref } from "vue";

const router = useRouter();
console.log(router.getRoutes());
const role = computed(() => {
  return localStorage.getItem("role");
});
console.log(role, 11111);

const list: any = ref([]);
if (role.value == "1") {
  console.log(role);

  list.value = router.getRoutes().filter((v) => v.meta.isShow || v.meta.isAdmin);
  console.log(list.value, 1);
} else {
  console.log(role);

  list.value = router.getRoutes().filter((v) => v.meta.isShow);
  console.log(list.value, 1);
}
const logout = () => {
  localStorage.clear();
  router.push("/login");
};
const url = computed(() => {
  return localStorage.getItem("url");
});
const username = computed(() => {
  return localStorage.getItem("username");
});
console.log(username.value, "username");
</script>

<style lang="scss" scoped>
.el-header {
  height: 80px;
  background-color: #666;
  .logo {
    height: 80px;
  }
  h2,
  .quit-login {
    text-align: center;
    height: 80px;
    line-height: 80px;
    color: white;
  }
}
.el-aside {
  .el-menu {
    height: calc(100vh - 80px);
  }
}
.el-main {
  --el-main-padding: 10px;
}
.example-showcase .el-dropdown-link {
  cursor: pointer;
  color: var(--el-color-primary);
  display: flex;
  align-items: center;
}
</style>
